{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format = 'retina'\n",
    "\n",
    "import torchvision.models as models\n",
    "\n",
    "from flashtorch.activmax import GradientAscent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = models.vgg16(pretrained=True)\n",
    "g_ascent = GradientAscent(model.features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "conv1_2 = model.features[2]\n",
    "conv1_2_filters = [17, 33, 34, 57]\n",
    "\n",
    "g_ascent.visualize(conv1_2, conv1_2_filters, num_iter=1, title='conv1_2');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "conv5_1 = model.features[24]\n",
    "conv5_1_filters = [45, 271, 363, 409]\n",
    "\n",
    "g_ascent.visualize(conv5_1, num_iter=1, title='Randomly selected filters from conv5_1');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g_ascent.visualize(conv5_1, 3, num_iter=1, title='conv5_1 filter 3');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g_ascent.visualize(conv5_1, 3, num_iter=1, title='conv5_1 filter 3', return_output=True);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g_ascent.deepdream('./resources/test_image.jpg', conv5_1, 33, num_iter=1);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g_ascent.optimize(conv5_1, 3, num_iter=1);"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
